package guo;

public class String_StringBuffer_StringBuilder {
    public static void main(String[] args) {
        StringBuilder sb = new StringBuilder();

        Runnable task = () -> {
            for (int i = 0; i < 1000; i++) {
                sb.append("a");
            }
        };

        Thread thread1 = new Thread(task);
        Thread thread2 = new Thread(task);

        thread1.start();
        thread2.start();

        try {
            thread1.join();
            thread2.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println(sb.length()); // 期望结果为2000  出现竞态条件，结果取决于线程执行顺序
    }
}
